package com.mz.mattress.client.api.biz;

import com.mz.mattress.api.common.Result;
import com.mz.mattress.api.entity.MemberCoupon;
import com.mz.mattress.api.enums.CouponSendTypeEnum;
import com.mz.mattress.api.jwt.ClientJwt;
import com.mz.mattress.client.common.Holder;
import com.mz.mattress.client.service.CouponService;
import com.mz.mattress.client.service.MemberCouponService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("memberCoupon")
public class MemberCouponController {

    @Autowired
    private MemberCouponService memberCouponService;

    @Autowired
    private CouponService couponService;

    @GetMapping("/list")
    public Result<List<MemberCoupon>> list(@RequestParam(required = false) Integer money, @RequestParam(required = false) Integer goodsId) {
        ClientJwt clientJwt = Holder.CLIENT_JWT_THREAD_LOCAL.get();
        return memberCouponService.list(clientJwt.getMemberId(), clientJwt.getMobile(), money, goodsId);
    }

    @GetMapping("/sendCoupon")
    public Result sendCoupon() {
        ClientJwt clientJwt = Holder.CLIENT_JWT_THREAD_LOCAL.get();
        Long memberId = clientJwt.getMemberId();
        couponService.sendCoupon(memberId, CouponSendTypeEnum.NEW_REGISTER);
        return Result.ok();
    }

}
